package com.mall.coupon.server.controller;

import com.mall.common.core.domain.Result;
import com.mall.coupon.common.domain.domain.Coupon;
import com.mall.coupon.common.domain.domain.UserCouponMiddle;
import com.mall.coupon.server.service.CouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.concurrent.ExecutionException;

/**
 * @ClassName couponController
 * @Description 描述
 * @Author Qiu Feng
 * @Date 2025/1/13 14:39
 */
@RestController
@RequestMapping("/coupon")
@CrossOrigin
public class CouponController {
    @Autowired
    private CouponService couponService;



    /**
     * 用户领取优惠券
     */
    @PostMapping("/add/{id}")
    public void userCouponAdd(@PathVariable Integer id){
        couponService.userCouponAdd(id);
    }

    /**
     * 用户已领取优惠卷列表
     */
    @GetMapping("/userCouponMiddleList/{couponStatus}")
    public Result<List<UserCouponMiddle>> userCouponMiddleList(@PathVariable Integer couponStatus) throws ExecutionException, InterruptedException {
        List<UserCouponMiddle> userCouponMiddles = couponService.userCouponMiddleList(couponStatus);
        Result success = Result.success(userCouponMiddles);
        return success;
    }

    /**
     * 选择可用优惠券列表
     */
    @GetMapping("/settlementList/{skuId}")
    public Result<List<Coupon>> filteredCoupons(@PathVariable List<Long> skuId){
        List<Coupon> coupons = couponService.filteredCoupons(skuId);
        Result<List<Coupon>> success = Result.success(coupons);
        return success;
    }


    /**
     * 优惠券已使用状态修改
     */
    @PutMapping("/update/{id}")
    public void updateUserCouponMiddleStatus(@PathVariable Integer id){
        couponService.updateUserCouponMiddleStatus(id);
    }
}
